package com.zcl.Thread.t3;

/**
 * @Description:
 * @author: zcl
 * @date: 2022/3/9  16:47
 *创建多线程的方式二: 实现Runnable接口
 * 1.创建一个实现了Runnable接口的类
 * 2.实现类去实现Runnable接口中的抽象方法: run()方法
 * 3.创建实现类对象
 * 4.将此对象作为参数传递到Thread类的构造器中,创建Thread类对象
 * 5.通过Thread类对象调用start()方法
 */


class Trunnable implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            if (i%2==0){
                System.out.println(Thread.currentThread().getName()+ ": "+ i);
            }
        }
    }
}

public class ThreadRunnable {
    public static void main(String[] args) {
        Trunnable trunnable = new Trunnable();
        Thread thread1 = new Thread(trunnable);
        thread1.setName("线程1");
        thread1.start();

        Thread thread2 = new Thread(trunnable);
        thread2.setName("线程2");
        thread2.start();

    }
}
